package com.jt.rabbitmq.topics;

import com.jt.utils.ConnectionUtil;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/*主题模式*/
public class Producter {
    private static final String exchangeName = "topics——exchange";
    private static final String QUEUE_NAME1 = "topics-test1";
    private static final String QUEUE_NAME2 = "topics-test2";
    private static final String QUEUE_NAME3 = "topics-test3";
    public static void main(String[] args) throws IOException, TimeoutException {
        ConnectionUtil connectionUtil=new ConnectionUtil();
        Connection connection = connectionUtil.getConnection();
        Channel channel = connection.createChannel();
        channel.exchangeDeclare(exchangeName, BuiltinExchangeType.TOPIC, true, false, false, null);
        channel.queueDeclare(QUEUE_NAME1, true, false, false, null);
        channel.queueDeclare(QUEUE_NAME2, true, false, false, null);
        channel.queueDeclare(QUEUE_NAME3, true, false, false, null);
        channel.queueBind(QUEUE_NAME1,exchangeName,"#.error");
        channel.queueBind(QUEUE_NAME2,exchangeName,"order.*");
        channel.queueBind(QUEUE_NAME3,exchangeName,"*.*");
        channel.basicPublish(exchangeName,"order.info",null,"主题模式测试".getBytes());
        channel.close();
        connection.close();
    }
}
